export default {
    props: {
        value: {
            ignore: true
        }
    },
    data() {
        return {
            model: this.value
        }
    },
    watch: {
        value(newValue) {
            this.model = newValue
        },
        model(newValue) {
            this.$emit('input', newValue)
        }
    },
    computed: {
        mixinProps() {
            const props = this.$options.props
            return Object.keys(props).reduce((ins, key) => {
                const val = props[key]
                if (val instanceof Object && val['ignore'] === true) {
                    return ins
                }
                ins[key] = this.$props[key]
                return ins
            }, {...this.$attrs})
        },
        mixinEvents() {
            return Object.keys(this.$listeners).reduce((ins, key) => {
                if (key !== 'input') {
                    ins[key] = (...args) => this.$emit(key, ...args)
                }
                return ins
            }, {})
        },
        slotKeys() {
            return Object.keys({...this.$slots})
        },
        scopedSlotKeys() {
            return Object.keys({...this.$scopedSlots})
        }
    },
    beforeCreate() {
        const root = this.$options.root
        if (root) {
            const props = this.$options.props
            Object.keys(root.props || {}).forEach(key => {
                if (!props[key]) {
                    props[key] = root.props[key]
                }
            })

            const methods = this.$options.methods
            Object.keys(root.methods || {}).forEach(key => {
                if (!methods[key]) {
                    methods[key] = (...args) => {
                        if (this.$refs.root && this.$refs.root[key] instanceof Function) {
                            this.$refs.root[key](...args)
                        }
                    }
                }
            })
        }
    },
}